<?php
/*
	我的购物车
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['lang']){
	$_SESSION['show_lang']=$_RQ['lang'];
}
//未登录下单
$return['ischecklogin']=$this->model('member')->checklogin('','','','',true);
$return['item']=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
if(!$return['item'] && !$_RQ['isstore']){
	$_SESSION['uid']=0;
	//exi('找不到会员信息！请先登陆！','error','jy_weishop/account.login/');
}
$store_id=$_SESSION['store_id'];
if($_RQ['op']=='main'){
	//$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	$return['params']=array();
	$return['cartnums']= pdo_getsum('jy_weishop_member_cart',array('mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']),'total');
	$return['feemoney']=$this->plugin_setting('feemoney');
	set_html('title','我的购物车');
	exi($return);
}
// js 获取数据
if($_RQ['op']=='getlist'){
	$ismerch=intval($_RQ['ismerch']);
	if($_RQ['store_id']){
		$_SESSION['store_id']=intval($_RQ['store_id']);
		$store_id=$_SESSION['store_id'];
	}
	$params=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
	);
	//未登录下单
	if(!$_SESSION['uid']){
		$return['list']=$_SESSION['cartlist']?:array();
		exi($return);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 100;
	$total='';
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'id desc',
	);
	$list=$this->pdo_getlist('member_cart',$parameter,$total);
	if($list){
		$feemoneyset=$this->plugin_setting('feemoney');
		$feemoneyset['feerade']=$feemoneyset['feerade']?:5;
		foreach($list as $k=>&$item){
			$goodsfile=array('id','isendtime','endtime','status','fang_credit2','no_de_sales','isdiyprice','diyprice','invoice','type','buylevels','buygroups','title','merchid','status','pcate','ccate','total','subtitle','image','video','price','totalcnf','weight','active_plugin','active_id','storeids','salenum','pluginname','originalprice','usermaxbuy','minbuynum','unit','isverify','diyfields','api_id','api_pluginname');
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid']),$goodsfile);
			if(!$goods['id']){
				$this->pdo_delete('member_cart',array('id'=>$item['id'],'uniacid'=>$_SESSION['uniacid']));
				unset($list[$k]);
				continue;
			}
			unset($item['storeid']);
			if($_SESSION['is_tomedia']){
				$goods['image']=$goods['image']?tomedia($goods['image']):'';
			}
			$item['merchid']=$goods['merchid'];
			//获取活动信息
			$goods['storeid']=$store_id;
			$goods['optionid']=$item['optionid'];
			$goods=$this->model('activity')->get_upgoods($goods);
			$item['oldprice']=$goods['oldprice'];
			$item['price']=$goods['price'];
			if($feemoneyset['isopen']==1){
				$item['feemoney']=$goods['marketprice']>0?$goods['marketprice']-$goods['price']:$feemoneyset['feerade']*$goods['price']/100;
				$item['feemoney']=price($item['feemoney']);
			}
			$goods['userbuy'] = 1;
			$goods['levelbuy'] = 1;
			$goods['groupbuy'] = 1;
			$goods['canbuy'] = ($goods['status'] == 1) && ($goods['total'] > 0);
			if (0 < $goods['usermaxbuy']) {
				$order_goodscount = pdo_getsum('jy_weishop_order_goods',array('ispay'=>1,'goodsid' => $goods['id'],'uniacid' => $_SESSION['uniacid'],'mid' => $_SESSION['uid']),'total');
				$isselect=pdo_getsum('jy_weishop_member_cart',array('selected'=>1,'optionid <>'=>$item['optionid'],'goodsid' => $goods['id'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'total');
				if ($goods['usermaxbuy'] <= $order_goodscount + $isselect) {
					$goods['userbuy'] = 0;
					$goods['canbuy'] = false;
					pdo_update('jy_weishop_member_cart',array('selected'=>2),array('id'=>$item['id'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
				}
				$goods['order_goodscount']=$order_goodscount;
			}
			if ((0 < $goods['isendtime']) && (0 < $goods['endtime']) && ($goods['endtime'] < time())) {
				$goods['canbuy'] = false;
			}
			$item['kucun']=$goods['total'];
			if($item['optionid']){
				$item['option']=$goods['options'];
				$item['kucun']=$item['option']['stock'];
				if(!$goods['options']['specs']){
					$optiontitle=$goods['options']['title'];
					$goods['istaocan'] = 1;
				}else{
					$specs = explode("_", $item['option']['specs']);
					$specsall = pdo_getall('jy_weishop_goods_spec_item',array('id'=>$specs,'uniacid'=>$_SESSION['uniacid']),array('id','title'),'','paixu asc');
					if($specsall){
						$optiontitle='';
						foreach($specsall as $k=>&$sp){
							if($k==0){
								$optiontitle .=$sp['title'];
							}else{
								$optiontitle .='，'.$sp['title'];
							}
						}
					}
				}
				$item['optiontitle']= $optiontitle;
				if($item['option']['stock']<1){
					$goods['canbuy'] = false;
				}
			}
			//判断nobuy状态：
			$unit=$goods['unit']?:'件';
			if($goods['userbuy']==0){
				$goods['nobuytitle']='已超出最大'.$goods['usermaxbuy'].'件购买量';
			}elseif($goods['levelbuy']==0){
				$goods['nobuytitle']='您当前会员等级没有购买权限';
			}elseif($goods['groupbuy']==0){
				$goods['nobuytitle']='您所在的用户组没有购买权限';
			}elseif($goods['timebuy']==-1){
				$goods['nobuytitle']='未到开始抢购时间!';
			}elseif($goods['timebuy']==1){
				$goods['nobuytitle']='抢购时间已经结束';
			}else{
				$goods['nobuytitle']='商品已售罄';
			}
			if ($goods['usermaxbuy'] && $goods['usermaxbuy'] < $order_goodscount + $item['total']) {
				$goods['outnumtitle']='超购买量,请减少';
				$goods['outtype']=1;
			}
			if($item['kucun']<$item['total']){
				$goods['outnumtitle']='超库存,请减少';
				$goods['outtype']=2;
			}
			if($goods['minbuynum'] && $item['total']<$goods['minbuynum']){
				$goods['outnumtitle']='单次最少购买'.$goods['minbuynum'].$unit;
				$goods['outtype']=3;
			}
			if($goods['maxbuy'] && $item['total']>$goods['maxbuy']){
				$goods['outnumtitle']='单次最多购买'.$goods['minbuynum'].$unit;
				$goods['outtype']=4;
			}
			$sales=$this->model('activity')->get_sales($goods['id']);
			if($sales['maxnum']>0 && $item['total']>$sales['maxnum']){
				$goods['outnumtitle']='只能购买活动品'.$sales['maxnum'].$unit;
				$goods['outtype']=5;
			}
			if($goods['outtype'] || !$goods['canbuy']){
				pdo_update('jy_weishop_member_cart',array('selected'=>0),array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['id']));
				$item['selected']=0;
			}
			$goods['weight']=$this->pdo_getcolumn('goods_dispatch',array('goodsid'=>$item['goodsid']),'weight');
			$goods['total']=intval($goods['total']);
			$item=array_merge($goods,$item);
		}
		if($ismerch){
			$nowplugin=$_SESSION['current_plugin']?:'jy_weishop';
			$menus_index=$_SESSION['menus_index']?:$nowplugin.'/index/';
			$merchs=array();
			$selectmerch=$this->session('selectmerch')?:array();
			foreach($list as $lv){
				$goods=$lv;
				$merchid=intval($lv['merchid']);
				if($merchid && empty($merchs[$merchid])){
					$selectmerch[$merchid]=isset($selectmerch[$merchid])?$selectmerch[$merchid]:1;
					$merch=pdo_get('jy_merch_user',array('id'=>$merchid),array('id','merchname'));
					if(!$merch['id']){
						continue;
					}
					$merch['coupons']=$this->model('coupon')->getmerchcoupon($merchid,1);
					$merchs[$merchid]=array(
						'selected'=>$selectmerch[$merchid],
						'total'=>0,
						'totalprice'=>0,
						'typename'=>'商户',
						'merchid'=>$merchid,
						'merch'=>$merch,
						'url'=>'jy_merch/myshop//id='.$merchid,
					);
				}
				if(!$merchid && empty($merchs[$merchid])){
					$selectmerch['-1']=isset($selectmerch['-1'])?$selectmerch['-1']:1;
					$merch=array('merchname'=>'平台自营','id'=>0);
					$merch['coupons']=$this->model('coupon')->getmerchcoupon(0,1);
					$merchs[0]=array(
						'selected'=>$selectmerch['-1'],
						'total'=>0,
						'totalprice'=>0,
						'typename'=>'平台',
						'merchid'=>'-1',
						'merch'=>$merch,
						'url'=>$menus_index,
					);
					if($goods['store_isopen'] && !$merchs[0]['store_isopen']){
						$store=pdo_get('jy_weishop_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$goods['storeid']),array('id','title','pcd','address'));
						$store['pcd']=$store['pcd']?json_decode($store['pcd'],true):array();
						if($store['id']){
							$merchs[0]['store_isopen']=1;
						}
						$merchs[0]['store']=$store;
					}
				}
				$merchs[$merchid]['goods'][]=$goods;
				if($goods['selected']){
					$merchs[$merchid]['total'] +=$goods['total'];
					$merchs[$merchid]['totalprice'] +=$goods['total']*$goods['price'];
				}
			}
			$this->session('selectmerch',$selectmerch);
			$list=$merchs;
		}
	}
	$list=array_values($list);
	$return['list']=$list;
	exi($return);
}
if($_RQ['op']=='plus'){
	//增加
	$post=get_postdata();
	$id=intval($post['id']);
	if(!$id){
		exi('请先选择商品！','error');
	}
	$cart=pdo_get('jy_weishop_member_cart',array('id'=>$id),array('id','total','goodsid','optionid'));
	$this->model('goods')->check_buy($cart['goodsid'],intval($cart['total'])+1,intval($cart['optionid']),true,true);
	if($cart['optionid']){
		$this->model('cart')->check_select($cart);
	}
	pdo_update('jy_weishop_member_cart',array('total +='=>1),array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('success');
}
if($_RQ['op']=='minus'){
	//减少
	$post=get_postdata();
	$id=intval($post['id']);
	$goodsid=intval($post['goodsid']);
	$isnotgoodsid=intval($_RQ['isnotgoodsid']);
	$optionid=intval($post['optionid']);
	$merchid=intval($post['merchid']);
	$store_id=intval($post['storeid'])?:intval($post['store_id']);
	if(!$id && !$goodsid){
		exi('请先选择商品！','error');
	}
	if($id){
		$check=pdo_get('jy_weishop_member_cart',array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('total','goodsid','optionid'));
	}elseif($goodsid){
		$check=pdo_get('jy_weishop_member_cart',array('optionid'=>$optionid,'goodsid'=>$goodsid,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','total','goodsid','optionid'));
		$id=$check['id'];
	}
	if(!$check){
		//return false;
		exi('指定商品不存在！'.$id,'error');
	}
	if($check['total']<=1){
		$this->pdo_delete('member_cart',array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		if($post['getlist']){
		}elseif($post['wxapp']){
			exi('success');
		}else{
			exi('删除成功!');
		}	
	}elseif($check){
		//减少时不核实，这样可以清空购物车
		//$this->model('goods')->check_buy($check['goodsid'],intval($check['total'])-1,intval($check['optionid']),true);
		pdo_update('jy_weishop_member_cart',array('total -='=>1),array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
		if($post['getlist']){
		}else{
			exi('success');
		}
	}
	$allcart=$this->model('cart')->getall('',$merchid,$isnotgoodsid,$store_id);
	//运费计算：
	if($merchid){
		$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	}
	$order=array(
		'list'=>$allcart['list'],
		'total_price'=>$allcart['goodsprice'],
	);
	if(!$merchid){
		$up_dispatch=$this->model('order/dispatch')->up_dispatch($order,array(),'',$_SESSION['store_id'],$merch);
	}
	$res['dispatchprice']=$up_dispatch['get_freight']['fee']?:0;
	$res['list']=$allcart['list'];
	exi($res);
}
if($_RQ['op']=='addtocart'){
	$post=get_postdata();
	$id=intval($post['goodsid']);
	$store_id=intval($post['storeid'])?:intval($post['store_id']);
	$merchid=intval($post['merchid']);
	$number=intval($post['num']);
	$isnotgoodsid=intval($_RQ['isnotgoodsid']);
	if(!$id){
		exi('选择的商品不存在，请重新选择！','error');
	}
	$this->model('activity/sales')->check_sale_new(array(array('goodsid'=>$id)));
	if(!$number){
		$number=1;
	}
	$spsids = '';
	$post['optionid']=$post['optionid']?:$post['optionsid'];
	if($post['specid']){
		foreach($post['specid'] as $k=>&$s){
			if($k==0){
				$spsids .= $s;
			}else{
				$spsids .= '_'.$s;
			}
		}
		$optionid = pdo_getcolumn('jy_weishop_goods_option',array('goodsid'=>$id,'specs'=>$spsids),'id');
	}
	if(!$optionid && $post['optionid']){
		$optionid=$post['optionid'];
	}
	$goods=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	if($store_id){
		$getinfo=model('jy_weishop/store')->getinfo($id,$store_id);
		$goods['total']=$getinfo['id']?$getinfo['total']:$goods['total'];
		$goods['price']=$getinfo['id']?$getinfo['price']:$goods['price'];
		if($optionid){
			$options=model('jy_weishop/store')->getoption($id,$store_id,'',$optionid);
		}
	}
	if(!$options['id'] && $optionid){
		$options = pdo_get('jy_weishop_goods_option',array('goodsid'=>$id,'id'=>$optionid));
	}
	$ifgoods=pdo_get('jy_weishop_member_cart',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'goodsid'=>$id,'optionid'=>$optionid));
	$data=array(
		'uniacid'=>$_SESSION['uniacid'],
		'mid'=>$_SESSION['uid'],
		'goodsid'=>$id,
		'price'=>$options['price']>0?$options['price']:$goods['price'],
		'optionid'=>$optionid,
		'selected'=>1,
	);
	$goods['api_data']=json_decode($goods['api_data'],true);
	if($goods['api_data']['no_paytype']){
		$no_paytype=str_array($goods['api_data']['no_paytype']);
		if($no_paytype){
			foreach($no_paytype as $nkey=>$nv){
				if(intval($nv)){
					unset($no_paytype[$nkey]);
				}
			}
			if($no_paytype && !$goods['api_data']['no_paytypecart']){
				exi('该商品启用了[不支持的支付方式]，不能加入购物车！','error');
			}
		}
	}
	if($ifgoods){
		$cartid=$ifgoods['id'];
		$data['total']=$ifgoods['total']+$number;
		$this->model('goods')->check_buy($data['goodsid'],intval($data['total']),intval($data['optionid']),true,true);
		pdo_update('jy_weishop_member_cart',$data,array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'id'=>$ifgoods['id']));
		if($post['getlist']){
		}else{
			exi('success');
		}
	}else{
		$data['total']=$number;
		$data['storeid']=$store_id;
		$this->model('goods')->check_buy($data['goodsid'],intval($data['total']),intval($data['optionid']),true,true);
		//如果来自其他商户分销（保存商户ID）
		$data['merchid']=$goods['merchid']?:$this->session('frommerchid');
		$data['pluginname']=$post['pluginname']?:'';
		pdo_insert('jy_weishop_member_cart',$data);
		$cartid=pdo_insertid();
	}
	$allcart=$this->model('cart')->getall('',$merchid,$isnotgoodsid,$store_id);
	//运费计算：
	if($merchid){
		$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	}
	$order=array(
		'list'=>$allcart['list'],
		'total_price'=>$allcart['goodsprice'],
	);
	if(!$merchid){
		$up_dispatch=$this->model('order/dispatch')->up_dispatch($order,array(),'',$_SESSION['store_id'],$merch);
	}
	$res['dispatchprice']=$up_dispatch['get_freight']['fee']?:0;
	$res['list']=$allcart['list'];
	$res['cartid']=$res['id']=$cartid;
	exi($res);
}
if($_RQ['op']=='check_buy'){
	$storeid=intval($_RQ['storeid']);
	$merchid=intval($_RQ['merchid']);
	$sendtype=intval($_RQ['sendtype']);
	$is_dish=intval($_RQ['is_dish']);
	$prams=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'selected'=>1);
	if($merchid){
		if($merchid==-1){
			$prams['merchid']=0;
		}else{
			$prams['merchid']=$merchid;
		}
	}
	$cart_list=pdo_getall('jy_weishop_member_cart',$prams,array('id','goodsid','total','optionid','merchid'));
	if(!$cart_list){
		exi('您的购物车没有选中商品！','error');
	}
	$this->model('cart')->check_buy($cart_list,'',$return['shopset']);
	$this->model('activity/sales')->check_sale_new($cart_list);
	if($_SESSION['ocreateurl']){
		$ocreateurl=links($_SESSION['ocreateurl']);
		if($ocreateurl['plugin']!=$_SESSION['current_plugin']){
			unset($_SESSION['ocreateurl']);
		}
	}
	$query='storeid='.$storeid.'&sendtype='.$sendtype.'&is_dish='.$is_dish.'&merchid='.$merchid;
	if($_SESSION['current_plugin']=='jy_weishopmeituan' || $_SESSION['current_plugin']=='jy_weidish' || $_SESSION['current_plugin']=='jy_weishoppei' || $_SESSION['current_plugin']=='jy_weishoppeishop' || $_SESSION['current_plugin']=='jy_weishopscale'){
		if($_SESSION['current_plugin']=='jy_weishoppeishop'){
			$resurl='jy_weishoppei/create//'.$query;
		}elseif($_SESSION['current_plugin']=='jy_weishopscale'){
			$resurl='jy_weishopscale/create//'.$query;
		}elseif($_SESSION['current_plugin']=='jy_weishopmeituan'){
			$resurl='jy_weishopmeituan/create//'.$query;
		}else{
			$resurl=$_SESSION['current_plugin'].'/create//'.$query;
		}
	}elseif($_SESSION['ocreateurl']){
		$resurl=$_SESSION['ocreateurl'].$query;
	}elseif($return['shopset']['ordercreateurl']){
		$resurl=$return['shopset']['ordercreateurl'].'/'.$query;
	}else{
		if(!$merchid && !$is_dish){
			$resurl='jy_weishop/order.create//'.$query;
		}else{
			$resurl='jy_weishop/order.create//'.$query;
		}
	}
	if($_RQ['isresurl']){
		exi($resurl);
	}else{
		exi('','',$resurl);
	}
}
if($_RQ['op']=='selectall'){
	$type=intval($_RQ['type']);
	pdo_update('jy_weishop_member_cart',array('selected'=>$type),array('selected'=>array(0,1),'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('success');
}
if($_RQ['op']=='select'){
	$post=get_postdata();
	$id=intval($post['id']);
	if(!$id){
		exi('请先选择商品！','error');
	}
	$check=pdo_get('jy_weishop_member_cart',array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','total','goodsid','optionid'));
	if(!$check){
		exi('指定商品不存在！','error');
	}
	if($post['selected'] && $check['optionid']){
		$this->model('cart')->check_select($check);
	}
	pdo_update('jy_weishop_member_cart',array('selected'=>intval($post['selected'])),array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('success');
}
if($_RQ['op']=='selectmerch'){
	$post=get_postdata();
	if($post['id']==-1){
        $post['id']=0;
    }
	$id=intval($post['id']);
	$selectmerch=$this->session('selectmerch')?:array('0'=>1);
	if($_RQ['isnew']){
        $selectmerch[$id]=intval($post['selected']);
    }else{
        $selectmerch[$id]= $selectmerch[$id]?0:1;
    }
	$this->session('selectmerch',$selectmerch);
    pdo_update('jy_weishop_member_cart',array('selected'=>$selectmerch[$id]),array('merchid'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi('success');
}
if($_RQ['op']=='offeradd'){
	$sale_offer=$this->model('activity/sales')->getoffer();
	foreach($sale_offer['list'] as $item){
		if($item['canbuy']){
			$data=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'goodsid'=>$item['id'],
				'price'=>$item['oldprice'],
				'optionid'=>$item['optionsid'],
				'selected'=>1,
			);
			$ifgoods=pdo_get('jy_weishop_member_cart',array('goodsid'=>$item['id'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','total'));
			if($ifgoods){
				$data['total']=$ifgoods['total']+1;
				pdo_update('jy_weishop_member_cart',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$ifgoods['id']));
			}else{
				$data['total']=1;
				//如果来自其他商户分销（保存商户ID）
				$data['total']['merchid']=$this->session('frommerchid');
				pdo_insert('jy_weishop_member_cart',$data);
			}
		}
	}
	exi('添加成功！');
}
if($_RQ['op']=='newadd'){
	$sale_new=$this->model('activity/sales')->getnew();
	foreach($sale_new['list'] as $item){
		if($item['cant_buy']!=1){
			$data=array(
				'uniacid'=>$_SESSION['uniacid'],
				'mid'=>$_SESSION['uid'],
				'goodsid'=>$item['id'],
				'price'=>$item['price'],
				'optionid'=>$item['optionsid'],
				'selected'=>1,
			);
			$ifgoods=pdo_get('jy_weishop_member_cart',array('goodsid'=>$item['id'],'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('id','total'));
			if($ifgoods){
				$data['total']=$ifgoods['total']+1;
				pdo_update('jy_weishop_member_cart',$data,array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'id'=>$ifgoods['id']));
			}else{
				$data['total']=1;
				//如果来自其他商户分销（保存商户ID）
				$data['total']['merchid']=$this->session('frommerchid');
				pdo_insert('jy_weishop_member_cart',$data);
			}
		}
	}
	exi('添加成功！');
}
if($_RQ['op']=='upcart'){
	$post=get_postdata();
	foreach($post as $k=>$total){
		if($total>0){
			pdo_update('jy_weishop_member_cart',array('total'=>$total),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid'],'id'=>$k));
		}
	}
	exi('success');
}
if($_RQ['op']=='del'){
	//删除
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	if(count($del)==0){
		exi('请先选择商品','error');
	}
	foreach($del as $id){
		$id=intval($id);
		$this->pdo_delete('member_cart',array('id'=>$id,'mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	}
	exi('删除成功！');
}
?>